import config from './config.js'

const isEmpty = function(v) {	 
	switch (typeof v) {
		case 'undefined':
			return true;
		case 'string':
			if (v.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0) return true;
			break;
		case 'boolean':
			if (!v) return true;
			break;
		case 'number':
			if (0 === v || isNaN(v)) return true;
			break;
		case 'object':
			if (null === v || v.length === 0) return true;
			for (var i in v) {
				return false;
			}
			return true;
	}
	return false;
}


const isLogin = function() {

	let token = uni.getStorageSync('token')
	if (!token) {
		//#ifdef MP-WEIXIN
		uni.navigateTo()({
			url: '../everyone/login'
		})
		//#endif
		//#ifdef H5
		uni.navigateTo({
			url: '../everyone/login'
		})
		//#endif
	} else {
		return token
	}

}

const getPlatform = function() {
	//#ifdef MP-WEIXIN
	return 'MPWEIXIN';
	//#endif
	//#ifdef H5
	return 'H5';
	//#endif
}
const navigateTo = function(path, param = '') {
	uni.navigateTo({
		url: path + param
	});
}

export default {
	isEmpty,
	isLogin,
	getPlatform,
	navigateTo

}
